package com.joysuch.wwyt.workflow.repository;

import com.joysuch.wwyt.workflow.entity.WorkFlowOptionType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface WorkFlowOptionTypeDao extends JpaRepository<WorkFlowOptionType, Long> {


    int countByOptionType(String optionType);

    //    @Query(value = "select * from wwyt_workflow_option_type where option_type like %?1% ",nativeQuery = true)
    @Query(value = "SELECT * FROM wwyt_workflow_option_type " +
            "WHERE id IN " +
            "(SELECT DISTINCT(t.id) FROM wwyt_workflow_option_type t, wwyt_workflow_option o " +
            "WHERE  t.id = o.option_type AND if(:optionType !='',t.option_type LIKE %:optionType% ,1=1) AND t.delete_flag = '0' AND o.delete_flag ='0') " +
            "ORDER BY id DESC", nativeQuery = true)
    List<WorkFlowOptionType> findByOptionTypeLike(@Param("optionType") String optionType);

    @Query(value = " select * from `wwyt_workflow_option_type` where option_type =?1 and delete_flag = '0' limit 1", nativeQuery = true)
    WorkFlowOptionType findByName(String optionTypeProxyName);
}
